package com.carrental.rental.controller;

import com.carrental.common.api.CommonResult;
import com.carrental.common.api.PageResult;


import com.carrental.rental.dto.OverdueFeeNoticeDTO;
import com.carrental.rental.dto.RentalRenewDTO;
import com.carrental.rental.dto.RentalStatusQueryDTO;
import com.carrental.rental.dto.RentalStatusReminderDTO;
import com.carrental.rental.service.RentalStatusService;
import com.carrental.rental.vo.RentalStatusVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.Map;

/**
 * 租赁状态跟踪控制器
 */
@RestController
@RequestMapping("/rental-status")
public class RentalStatusController {

    @Autowired
    private RentalStatusService rentalStatusService;

    /**
     * 分页查询租赁状态
     */
    @GetMapping("/page")
    public CommonResult<PageResult<RentalStatusVO>> page(RentalStatusQueryDTO queryDTO) {
        PageResult<RentalStatusVO> pageResult = rentalStatusService.getRentalStatusPage(queryDTO);
        return CommonResult.success(pageResult);
    }

    /**
     * 获取统计数据
     */
    @GetMapping("/stats")
    public CommonResult<Map<String, Object>> getStats() {
        Map<String, Object> stats = rentalStatusService.getRentalStats();
        return CommonResult.success(stats);
    }

    /**
     * 发送提醒
     */
    @PostMapping("/remind")
    public CommonResult<Void> sendReminder(@RequestBody @Valid RentalStatusReminderDTO reminderDTO) {
        rentalStatusService.sendReminder(reminderDTO);
        return CommonResult.success(null);
    }

    /**
     * 续租
     */
    @PostMapping("/renew")
    public CommonResult<Void> renew(@RequestBody @Valid RentalRenewDTO renewDTO) {
        rentalStatusService.renewRental(renewDTO);
        return CommonResult.success(null);
    }

    /**
     * 发送超期费用通知
     */
    @PostMapping("/overdue-notice")
    public CommonResult<Void> sendOverdueNotice(@RequestBody @Valid OverdueFeeNoticeDTO noticeDTO) {
        rentalStatusService.sendOverdueFeeNotice(noticeDTO);
        return CommonResult.success(null);
    }

    /**
     * 导出租赁状态数据
     */
    @GetMapping("/export")
    public void export(RentalStatusQueryDTO queryDTO, HttpServletResponse response) {
        rentalStatusService.exportRentalStatus(queryDTO, response);
    }

    /**
     * 生成租赁状态报表
     */
    @GetMapping("/report")
    public void generateReport(HttpServletResponse response) {
        rentalStatusService.generateRentalStatusReport(response);
    }
} 